<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
//use Illuminate\Support\Facades\Schema;

class AddField20231010 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('member_follow')) {
            Schema::create('member_follow', function (Blueprint $table){
                $table->id();
                $table->unsignedInteger('member_id')->index()->comment('会员ID');
                $table->unsignedInteger('follow_id')->index()->comment('关注会员ID');
                $table->timestamps();
                $table->comment = '会员关注表';
            });
        }

        Schema::table('publishers', function (Blueprint $table) {
            if (!Schema::hasColumn('publishers', 'can_examine')) {
                $table->tinyInteger('is_examine')->default(0)->comment('前台是否可以审核 0-否 1-是');
            }
        });



        \App\Models\Settings::where('name', 'rotation_chat')
            ->get()
            ->each(function ($v) {
                $data = [];
                foreach (explode(',', $v->value) as $item) {
                    $data[] = ['img' => $item, 'jump_id' => null];
                }

                $v->update(['value' => json_encode($data)]);
                flushMiniSettings($v->mini_type, 'special');
            });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
